<template>
  <!-- 公司工程履约管理 -->
  <base-breadcrumb :title="$route.meta.title">
    <searchData :searchData="searchArr" @search="search"></searchData>

    <a-card>
      <!-- <title-name :title="$route.meta.title"></title-name> -->
      <!-- 表格 -->
      <list-table
        ref="table"
        :page-keys="['pageNo', 'pageSize']"
        size="default"
        rowKey="id"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        showPagination="auto"
      >
        <template slot="action" slot-scope="text, record">
          <MoreButton>
            <a v-btnPermission="[{code:'seex_pm_050_loo_01',ident:'prma_seex'},{code:'buco_pm_050_loo_01',ident:'prma_buco'}]" @click="handleManage(0, record)">查看</a>
            <!-- 编辑 -->
            <span v-if="record.auditStatus === 0 && hideBuquBtn()">
              <a-divider type="vertical" />
              <a @click="handleManage(1, record)">编辑</a>
            </span>
            <span v-if="record.auditStatus === 1">
              <a-divider type="vertical" />
              <a
                @click="
                  visible = true
                  currentRecord = record
                "
                >导出</a
              >
            </span>
          </MoreButton>
        </template>
      </list-table>
    </a-card>
    <a-modal title="导出" :visible="visible" :confirm-loading="confirmLoading" @ok="handleOk" @cancel="visible = false">
      <a-row
        ><a-col :span="24">请选择要导出的项目类型：</a-col
        ><a-col :span="24" class="mt12">
          <a-radio-group v-model="value">
            <a-radio :value="1"> 重点项目 </a-radio>
            <a-radio :value="2"> 所有项目 </a-radio>
          </a-radio-group></a-col
        ></a-row
      >
    </a-modal>
  </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import BasePage from '@/views/basePage' // 基础配置
import { api } from '@/api/project/performanceAnalysis'
import MoreButton from '@/components/MoreButton'
import PermissionTreeOrganization from '@/components/businessComponents/PermissionTreeOrganization'

const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    customRender() {
      return arguments[2] + 1
    }
  },
  {
    title: '月份',
    dataIndex: 'month',
    width: 120,
    ellipsis: true
  },
  {
    title: '当期累计完成产值/亿元',
    dataIndex: 'completionTotal',
    width: 180,
    ellipsis: true
  },
  {
    title: '产值完成率',
    width: 120,
    dataIndex: 'completionRate',
    ellipsis: true
  },
  {
    title: '人均产值/万元',
    width: 150,
    dataIndex: 'completionPre',
    ellipsis: true
  },
  {
    title: '工期履约率',
    width: 120,
    dataIndex: 'periodRate',
    ellipsis: true
  },
  {
    title: '节点按时完成率',
    width: 140,
    dataIndex: 'nodeRate',
    ellipsis: true
  },
  {
    title: '实名制出勤率',
    dataIndex: 'realnameRate',
    width: 140,
    ellipsis: true
  },
  {
    title: '顾客满意度',
    width: 140,
    dataIndex: 'satisfaction',
    ellipsis: true
  },
  {
    title: '状态',
    width: 120,
    dataIndex: 'auditStatusStr'
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: 200,
    scopedSlots: { customRender: 'action' }
  }
]
const searchArr = [
  {
    name: '月份',
    type: 'monthRange',
    value: 'mealMonthTime',
    attr: {
      rangeFormat: ['monthStart', 'monthEnd']
    }
  },

  {
    name: '状态',
    value: 'auditStatus',
    type: 'select',
    data: [
      {
        value: 0,
        label: '待提交'
      },
      {
        value: 1,
        label: '已提交'
      }
    ]
  }
]
export default {
  name: 'a' + Date.now(),
  extends: new BasePage(),
  components: {
    STable,
    MoreButton,
    PermissionTreeOrganization
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      queryParam: {}, // 查询参数
      select: {},
      collapsed: false,
      visible: false,
      value: '',
      confirmLoading: false,
      currentRecord: {},
      removeApi: { remove: api.delNoAssessment },
      loadData: async (parameter) => {
        this.queryParam.branchCompanyId = undefined
        this.queryParam.projectId = this.select.projectId || undefined
        if (this.select.tageCode === 'BC') {
          this.queryParam.branchCompanyId = this.select.orgId
        }
        const requestParameters = Object.assign({}, parameter, { query: this.queryParam })

        return api.listLvyueCom(requestParameters).then((res) => {
          return res
        })
      }
    }
  },
  methods: {
    //搜索
    search(value) {
      value && (this.queryParam = value)
      console.log(11)
      this.$refs.table.refresh(true)
    },
    /**
     * @description: 树选中
     * @param {object} node 节点对象
     * @return {void}
     */
    handleSelect(node) {
      this.select = node
      if (this.select.tageCode != 'CO') {
        this.$refs.table.refresh(true)
      }
    },
    handleOk() {
      if (!this.value) {
        this.$message.warning('请选择导出项目类型')
        return
      }
      this.confirmLoading = true
      api.downExcelCom({ id: this.currentRecord.id, type: this.value }, '公司' + this.currentRecord.month + '履约分析.xls').then((res) => {
        this.confirmLoading = false
        this.visible = false
      })
    },
    // 操作栏
    async handleManage(type, record) {
      let query = {
        editModel: type
      }
      if (record && record.id) {
        query.id = record.id
      }
      this.$router.push({
        name: 'updateCompanyPerformanceAnalysis',
        query
      })
    }
  }
}
</script>
